﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace comm
{
    public static class EnumHelper
    {
        public static void CheckValueDefine(Type type, object value)
        {
            if (!Enum.IsDefined(type, value))
            {
                throw new Exception(type.Name + " " + value + " not define");
            }
        }
        public static void CheckValueDefine<T>(object value)
        {
            CheckValueDefine(typeof(T), value);
        }
        public static string[] GetNames(Type type)
        {
            var list = new List<string>();
            foreach (var fd in type.GetFields())
            {
                if (fd.Name != "value__")
                {
                    list.Add(fd.Name);
                }
            }
            return list.ToArray();
        }
        public static T Parse<T>(string value)
        {
            return (T)Enum.Parse(typeof(T), value);
        }
    }
}
